package com.ysd.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * 角色表
 * @author CJP
 *
 */
@Entity
@Table(name="roles")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Roles {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)//自动增长列
	private Integer rid;
	private String rname;
	@JsonIgnoreProperties("rlist")
	@ManyToMany(fetch=FetchType.EAGER) //多对多关系
	@Cascade(value={CascadeType.SAVE_UPDATE}) //级联关系
	@JoinTable(name="userroles", //指定第三张中间表名称
	 //本表主键 roleId 与第三张中间表 user_role_tb 的外键 user_role_tb_role_id 对应.本表与中间表的外键对应关系
	joinColumns={@JoinColumn(name="rid")}, //另一张表中间表的外键的对应关系
	inverseJoinColumns={@JoinColumn(name="uid")})
	@NotFound(action = NotFoundAction.IGNORE)//NotFound : 意思是找不到引用的外键数据时忽略，
	private List<User> ulist;//拿到用户集合
}
